﻿using HC.View;
using HC.Win32;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace EMRView
{
    public partial class DeEdit
    {
        public override void FormatToDrawItem(HCCustomData aRichData, int aItemNo)
        {
            base.FormatToDrawItem(aRichData, aItemNo);
            if (this.AutoSize)
            {
                //此处调整后，当设置了编辑单元宽度会识别为使用宽度，超过指定宽度为自动宽度
                var fixedWidth = int.Parse(this.Propertys["fixedWidth"]);
                if (fixedWidth > Width)
                {
                    Width = fixedWidth;
                }
            }
        }

        protected override void DoPaint(HCStyle aStyle, RECT aDrawRect, int aDataDrawTop, int aDataDrawBottom, int aDataScreenTop, int aDataScreenBottom, HCCanvas aCanvas, PaintInfo aPaintInfo)
        {
            base.DoPaint(aStyle, aDrawRect, aDataDrawTop, aDataDrawBottom, aDataScreenTop, aDataScreenBottom, aCanvas, aPaintInfo);
            if (string.IsNullOrEmpty(this.Text) && !aPaintInfo.Print)
            {
                var tipText = string.IsNullOrEmpty(this["Name"]) ? "未填写" : this["Name"];
                //当文本为空时使用Name属性值作为背景文字绘制，当Name耶为空时候，绘制“未填输入域”
                aCanvas.Font.FontStyles.InClude((byte)HCFontStyle.tsItalic);
                aCanvas.Font.Color = Color.Red;
                aCanvas.TextRect(ref aDrawRect, tipText, 0);
                //aCanvas.TextOut(aDrawRect.Left, aDrawRect.Top, tipText);
            }
        }


        public new int Width
        {
            get { return GetWidth(); }
            set
            {
                //扩展Width设置宽度，DeEdit允许设置固定宽度
                this.Propertys["fixedWidth"] = value.ToString();
                SetWidth(value);
            }
        }
    }
}
